package com.wave12.utility;

import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

public class PubFunction {
	
	// 产生全局唯一ID
	public static String makeGUID(){
		UUID uuid = UUID.randomUUID();
	    String id = uuid.toString();
	    id = id.replace("-", "");
	    return id;
	}
	
 	public static boolean isEmptyString(String str){
		if (str == null || str.equals("")){
			return true;
		}
		return false;
	}
	
	public static String HTMLEncode(String con) {
		String strCon = con;
		strCon = strCon.replace("&", "&amp;");
		strCon = strCon.replace(">", "&gt;");
		strCon = strCon.replace("<", "&lt;"); 
		strCon = strCon.replace("\"", "&quot;");
		return strCon;
	}
	 
	public static String HTMLDecode(String con) {
		String strCon = con;
		strCon = strCon.replace("&gt;", ">");
		strCon = strCon.replace("&lt;", "<"); 
		strCon = strCon.replace("&quot;", "\"");
		strCon = strCon.replace("&amp;", "&");
		return strCon;
	}
	
	public static boolean IsPcClient(HttpServletRequest request) {
		boolean bIsPc = false; 
		 String s1 = request.getHeader("user-agent");
		 if(s1.contains("Android")) {
			 System.out.println("Android移动客户端");
		 } else if(s1.contains("iPhone")) {
			 System.out.println("iPhone移动客户端");
		 }  else if(s1.contains("iPad")) {
			 System.out.println("iPad客户端");
		 }  else {
			 System.out.println("其他客户端");
			 bIsPc = true;
		 } 
		 return bIsPc;
	}
	
}
